package force;

import assembly.Mass;
import java.util.Scanner;
import simulation.SpringiesConstants;
import simulation.Model;
import util.Vector;


/**
 * Global gravity force that pulls in a single direction, independent of location
 * 
 * @author Dagbedji Fagnisse
 * @author Scott Valentine
 * 
 */
public class Gravity extends Force {
    private static final String KEYWORD = SpringiesConstants.GRAVITY_KEYWORD;
    private static final int TOGGLE_KEY = SpringiesConstants.GRAVITY_TOGGLE;
    private static final Double G_EARTH = 9.81;
    private static final Double DEFAULT_ANGLE = 90.0;

    private Vector myVector;

    /**
     * Default constructor. Build a sample Gravity object.
     */
    public Gravity () {
        this(DEFAULT_ANGLE, G_EARTH);
        // don't forget to untoggle force
        toggle();
    }

    /**
     * Main constructor
     * 
     * @param angle the angle in degrees.
     * @param magnitude the magnitude of gravity.
     */
    public Gravity (double angle, double magnitude) {
        myVector = new Vector(angle, magnitude);
        toggle();
    }

    @Override
    public Vector getForceOn (Mass m) {
        // System.out.print(m.getID() + "\t" + isForceOn() + "\n");
        if (!isForceOn()) { return new Vector(); }
        return myVector;
    }

    @Override
    public Force load (Scanner line, Model model) {
        Double degrees = line.nextDouble();
        Double magnitude = line.nextDouble();
        return new Gravity(degrees, magnitude);
    }

    @Override
    public String getKeyword () {
        return KEYWORD;
    }

    @Override
    public int getToggleKey () {
        return TOGGLE_KEY;
    }

}
